package com.relax.mybatis.plugin.sensitive.strategy.impl;

import org.apache.commons.lang3.StringUtils;

import com.relax.mybatis.plugin.sensitive.strategy.SensitiveStrategy;

/**
 * @author relax
 * @date 2022/07/05
 * @desc 电话号码脱敏策略
 */
public class PhoneSensitiveStrategy implements SensitiveStrategy {

    /**
     * <p>电话号码脱敏：显示最后四位</p>
     * 
     * <pre>
     * PhoneSensitiveStrategy.handle("1234")          = "1234"
     * PhoneSensitiveStrategy.handle("123456")        = "**3456"
     * PhoneSensitiveStrategy.handle("020-8981-1572") = "*********1572"
     * </pre>
     * 
     * @param data
     * @param symbol
     * @return
     */
    @Override
    public String handle(String data, String symbol) {
        int length = StringUtils.length(data);
        if (length <= 4) {
            return data;
        }
        return StringUtils.leftPad(StringUtils.right(data, 4), StringUtils.length(data), symbol);
    }

}
